//
//  Status.swift
//  sinaWB
//
//  Created by 杨运旺 on 15/11/17.
//  Copyright © 2015年 杨运旺. All rights reserved.
//

import UIKit


/// 微博数据模型
class Status:NSObject{
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博创建时间
    var created_at: String?
    /// 微博来源
    var source: String?
    /// 用户模型
    var user: User?
    /// 缩略图片字典数组地址
    var pic_urls: [[String: String]]?
    
    init(dict: [String:AnyObject]) {
        super.init()
         // 如果使用 KVC 时，value 是一个字典，会直接给属性转换成字典
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        // 判断 key 是否是 user
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                
                user = User(dict: dict)
            }
            
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {    }
    
    override var description: String {
        let keys = ["id","text","created_at","source","user","pic_urls"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
